;(function(){
	// 初始化Pjax
	$(document).pjax('a[data-pjax]', '#pjaxContent', {
		maxCacheLength:0,
		cache: false,
		fragment: "#pjaxContent"
	});

	$(document).on('pjax:send', function() { 
	  $('.loading-model').show(); 
	});

	$(document).on('pjax:complete', function() { 
	  $('.loading-model').hide(); 
	});
	
	$(document).on("pjax:timeout", function(event) {
		event.preventDefault();
	});


})();



;layui.config({
    version: false //一般用于更新模块缓存，默认不开启。设为true即让浏览器不缓存。也可以设为一个固定的值，如：201610
    , debug: false //用于开启调试模式，默认false，如果设为true，则JS模块的节点会保留在页面
	, base: '/static/backend/plugins/layui/lay/modules/' //自定义layui组件的目录
});

;layui.use(['layer', 'element', 'common', 'pop', 'tool', 'laydate'], function() {
	var layer = layui.layer,
		element = layui.element(),
		device = layui.device(), //设备信息
		common = layui.common,
    	laydate = layui.laydate;
	
	//阻止IE7以下访问
    if (device.ie && device.ie < 8) {
        layer.alert('最低支持ie8，您当前使用的是古老的 IE' + device.ie + '！');
    }
	
	// 监听侧栏导航
	element.on('nav(navTree)', function (elem) {
        //var url = $(elem).children('a').attr('data-url');
        //if (url == undefined) return;
		//common.loadContent(url);
	});
	
	window.common = common;
	window.PopModel = layui.pop;
	window.Tool = layui.tool;

    /** 列表页CheckBox事件 **/
    var checkBox = {
        args: [],
        bindEvent: function (){
            $(".list-table-body").on('click', '.ui-table-multi-select', this.MultiSelect);
            $(".list-table-head").on('click', '.ui-table-select-all', this.SelectAll);
        },
        push: function (args) {
            this.args.push(+args);
        },
        remove: function (args){
            var index = $.inArray(+args, this.args);
            this.args.splice(index,1);
        },
        hasId: function(args) {
            return !!($.inArray(+args, this.args) + 1);
        },
        SelectAll: function () {
            if($(this).is(':checked')) {
                $(".ui-table-multi-select").each(function(index, item){
                    checkBox.args.push(+$(item).attr('data-id'));
                    $(item).attr("checked", true);
                });
            } else {
                $(".ui-table-multi-select").attr("checked", false);
                checkBox.args = [];
            }

            media.batchOperation();
        },
        MultiSelect: function() {
            var _this = $(this);
            var dataId = +_this.attr('data-id');
            var index = $.inArray(dataId, media.args);
            if( index >= 0 ) {
                media.args.splice(index,1);
            } else {
                media.args.push(dataId);

            }
            media.batchOperation();
        },
        batchOperation: function () {
            console.log(media.args);
            if( media.args.length > 0 ) {
                $(".list-batch-operation a").removeClass("state-disabled");
            } else {
                $(".list-batch-operation a").addClass("state-disabled");
            }
        }
    }
});




